import db from "@/db/postgres";
import dayjs from "dayjs";

// 设置页面缓存时间
export const revalidate = 31536000;
export async function generateStaticParams() {
  const res = await db.query.contentBlog.findMany({
    columns: {
      path: true,
    },
  });
  return res.map((item) => ({ path: item.path }));
}
export default async function BlogInfo({
  params,
}: {
  params: Promise<{ path: string }>;
}) {
  const { path } = await params;
  const blog = await db.query.contentBlog.findFirst({
    where: (q, { eq }) => eq(q.path, path),
  });

  return (
    <article className="max-w-3xl mx-auto p-4">
      {blog ? (
        <>
          <h1 className="text-3xl font-bold mb-4">{blog.title}</h1>​
          <div className="prose lg:prose-xl">​{blog.text}​</div>
          <span>更新时间:{dayjs().format("YYYY-MM-DD HH:mm:ss")}</span>
        </>
      ) : (
        <div>404</div>
      )}
    </article>
  );
}
